

//
//  HJDiscoverController.m
//  12期传智微博HJ
//
//  Created by mac on 15-2-1.
//  Copyright (c) 2015年 jun. All rights reserved.
//

#import "HJDiscoverController.h"
#import "HJSearchBar.h"
@interface HJDiscoverController()<UITextFieldDelegate>

@property (nonatomic, weak) HJSearchBar *searchBar;
@end

@implementation HJDiscoverController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    HJSearchBar *searchBar = [[HJSearchBar alloc]init];
    searchBar.frame = CGRectMake(0, 0, 300, 30);
    self.navigationItem.titleView = searchBar;
    
    searchBar.delegate = self;
    self.searchBar = searchBar;
}
#pragma mark - UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    //添加按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
    
    //替换leftview
    self.searchBar.leftIconName = @"settings_statistic_triangle";
}
- (void)cancel
{
    //清除取消按钮
    self.navigationItem.rightBarButtonItem = nil;
    
    //关闭键盘
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    
    //还原leftview
    self.searchBar.leftIconName = @"searchbar_searchlist_search_icon";
}
#pragma mark - 监听scollerView的拖拽
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    //关闭键盘
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}
@end
